#ifndef __MEVALUATOR__
#define __MEVALUATOR__

@class MEvaluation, MExpr, MMathLink, MPacket;

@interface MEvaluator : NSObject
{
@protected
	MMathLink* _link;
	NSMutableArray* _evaluations;
	id _delegate;
}

+ (id) evaluator;
+ (id) evaluatorWithPath: (NSString*) path;
+ (id) evaluatorWithLink: (MMathLink*) link;
- (id) initWithLink: (MMathLink*) link;
- (void) dealloc;

- (MMathLink*) link;
- (CFRunLoopRef) runLoop;
- (void) setLink: (MMathLink*) link;
- (void) setLink: (MMathLink*) link runLoop: (CFRunLoopRef) runLoop;

- (id) delegate;
- (void) setDelegate: (id) delegate;

- (MExpr*) evaluate: (MExpr*) expr asynchronously: (BOOL) async;
- (MExpr*) evaluateInputForm: (NSString*) inputForm asynchronously: (BOOL) async;
- (MEvaluation*) currentEvaluation;
- (NSArray*) queuedEvaluations;

@end


@interface NSObject (MEvaluatorDelegate)

- (void) evaluationDidStart: (MEvaluation*) evaluation;
- (void) evaluationDidFinish: (MEvaluation*) evaluation;
- (void) evaluationInputNameDidChange: (MEvaluation*) evaluation;
- (void) evaluation: (MEvaluation*) evaluation didReceivePacket: (MPacket*) packet;

- (void) callPacket: (MEvaluator*) evaluator;
- (void) evaluatePacket: (MEvaluator*) evaluator;
- (void) returnPacket: (MEvaluator*) evaluator;
- (void) inputNamePacket: (MEvaluator*) evaluator;
- (void) enterTextPacket: (MEvaluator*) evaluator;
- (void) enterExprPacket: (MEvaluator*) evaluator;
- (void) outputNamePacket: (MEvaluator*) evaluator;
- (void) returnTextPacket: (MEvaluator*) evaluator;
- (void) returnExprPacket: (MEvaluator*) evaluator;
- (void) displayPacket: (MEvaluator*) evaluator;
- (void) displayEndPacket: (MEvaluator*) evaluator;
- (void) messagePacket: (MEvaluator*) evaluator;
- (void) textPacket: (MEvaluator*) evaluator;
- (void) inputPacket: (MEvaluator*) evaluator;
- (void) inputStrPacket: (MEvaluator*) evaluator;
- (void) menuPacket: (MEvaluator*) evaluator;
- (void) syntaxPacket: (MEvaluator*) evaluator;
- (void) suspendPacket: (MEvaluator*) evaluator;
- (void) resumePacket: (MEvaluator*) evaluator;
- (void) beginDialogPacket: (MEvaluator*) evaluator;
- (void) endDialogPacket: (MEvaluator*) evaluator;
- (void) userPacket:  (MEvaluator*) evaluator packet: (unsigned long) packet;
- (void) unknownPacket:  (MEvaluator*) evaluator packet: (unsigned long) packet;

@end

#endif /* __MEVALUATOR__ */
